package dhm.com.dhmshop.fragment.wode.shop;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import dhm.com.dhmshop.R;
import dhm.com.dhmshop.adapter.home.ShopHomeAdapter;
import dhm.com.dhmshop.adapter.mine.ShopAdapter;
import dhm.com.dhmshop.base.BaseFragment;
import dhm.com.dhmshop.base.Presenter.PressenterImpl;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.base.netWork.LoginContract;
import dhm.com.dhmshop.entity.Bean;
import dhm.com.dhmshop.entity.GetMyShopinfo;
import dhm.com.dhmshop.entity.GetShopDetailBean;
import dhm.com.dhmshop.framework.module.commodity.activity.CommodityDetailsActivity;
import dhm.com.dhmshop.framework.module.home.activity.SearchActivity;
import dhm.com.dhmshop.utils.SpUtils;
import dhm.com.dhmshop.view.mine.myshop.ShowshopActivity;

@SuppressLint("ValidFragment")
public class ShopFregment extends BaseFragment{
    Unbinder unbinder;
    @BindView(R.id.recy)
    XRecyclerView recy;
    private View rootView;
    private List<GetMyShopinfo.DataBean> allgoods;
    private final GetShopDetailBean shopDetail;


    public ShopFregment(GetShopDetailBean getShopDetailBean) {
//        1、推荐  2、全部宝贝   3、新品
//        this.type = type;
        shopDetail = getShopDetailBean;
//        this.shop_type = shop_type;
    }


    @Override
    protected int getLayout() {
        return R.layout.shop_fragment;
    }

    @Override
    protected void initView() {
//        pressenter=new PressenterImpl();
//        pressenter.attachView(this);
        ShopHomeAdapter shopHomeAdapter=new ShopHomeAdapter(getActivity());
        LinearLayoutManager manager=new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recy.setAdapter(shopHomeAdapter);
        recy.setLayoutManager(manager);
        shopHomeAdapter.setGetShopDetailBean(shopDetail);
    }
    @Override
    protected void initData() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.shop_fragment, container, false);
        }
        unbinder = ButterKnife.bind(this, rootView);
        initView();
        return rootView;
    }



    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    int position=0;
//    @Override
//    public void requesta(Object data) {
//        if (data instanceof GetMyShopinfo){
//            getMyShopinfo = (GetMyShopinfo) data;
//            if (getMyShopinfo.getCode()==1){
//                if (allgoods==null||allgoods.size()==0){
//                    allgoods = getMyShopinfo.getData();
//                    shopAdapter = new ShopAdapter(getActivity());
//                    shopAdapter.setdeleteClick(new ShopAdapter.OnClick() {
//                        @Override
//                        public void item(int posttion) {
//                            position=posttion;
//                            Map map=new HashMap();
//                            map.put("uid",uid);
//                            map.put("token", Constant.TOKEN);
//                            map.put("goods_id",allgoods.get(posttion).getGoods_id()+"");
//                            pressenter.sendMessage(getActivity(),Constant.DeleteGoods,map, Bean.class);
//                        }
//                    });
//                    shopAdapter.seteditClick(new ShopAdapter.OneditClick() {
//                        @Override
//                        public void item(int posttion) {
//                            Intent intent=new Intent(getActivity(), ShowshopActivity.class);
//                            intent.putExtra("type","edit");
//                            intent.putExtra("shop_id",shop_id+"");
//                            intent.putExtra("goods_type",allgoods.get(posttion).getShop_type()+"");
//                            intent.putExtra("shop_type",shop_type+"");
//                            intent.putExtra("gid",allgoods.get(posttion).getGoods_id()+"");
//                            startActivity(intent);
//                        }
//                    });
//                    shopAdapter.setaddClick(new ShopAdapter.OnIntentClick() {
//                        @Override
//                        public void item(int posttion) {
//                            Intent intent=new Intent(getActivity(), CommodityDetailsActivity.class);
//                            intent.putExtra("gid",allgoods.get(posttion).getGoods_id());
//                            intent.putExtra("shop_id",Integer.parseInt(shop_id));
//                            intent.putExtra("idshop","1");
//                            startActivity(intent);
//                        }
//                    });
//                    recy.setAdapter(shopAdapter);
//
//                }else {
//                    allgoods.addAll(getMyShopinfo.getData());
//                }
//                offset++;
//                shopAdapter.setShopList(allgoods);
//
//            }else {
//                Toast.makeText(getActivity(), getMyShopinfo.getMessage(), Toast.LENGTH_SHORT).show();
//            }
//            recy.loadMoreComplete();
//            recy.refreshComplete();
//        }else if (data instanceof Bean){
//            Bean bean= (Bean) data;
//            Toast.makeText(getActivity(), bean.getMessage(), Toast.LENGTH_SHORT).show();
//            if (bean.getCode()==1){
//                getMyShopinfo.getData().remove(position);
//                shopAdapter.notifyDataSetChanged();
//            }
//        }
//
//    }

//    @Override
//    public void fail(String error) {
//
//    }
}
